package BIZ;

import DAO.StatementOfIncomeDAO;
import DAO.UserDetailsDAO;
import javabean.statementOfIncome;

import java.util.List;

public class statementofncomeBiz {
    StatementOfIncomeDAO statementOfIncomeDAO = new StatementOfIncomeDAO();
    UserDetailsDAO userDetailsDAO = new UserDetailsDAO();

    //插入一条账单
    public int addbill(String userid, String carId1, String carId2, String carId3, String Money) {

        int addbill = statementOfIncomeDAO.insertBill(userid, carId1, carId2, carId3, Money);
        return addbill;
    }

    //退费或消费
    public String Refundorcost(String userid, String money) {

        UserBiz userBiz = new UserBiz();
        //先获取当前余额
        String nowbalance = userBiz.getuserbalance(userid);

        //计算退费后的余额
        int newBalance1 = (Integer.parseInt(nowbalance) - Integer.parseInt(money));

        String newBalance = newBalance1 + "";

        //进行退费功能
        boolean refund = userDetailsDAO.UpdateBalance(newBalance, userid);

        //返回退费后余额
        return newBalance;

    }

    //充值
    public String confirmcharge(String userid, String money) {

        UserBiz userBiz = new UserBiz();
        //先获取当前余额
        String nowbalance = userBiz.getuserbalance(userid);

        //计算充值后的余额
        int newBalance1 = (Integer.parseInt(nowbalance) + Integer.parseInt(money));

        String newBalance = newBalance1 + "";

        //进行充值功能
        boolean confirmcharge = userDetailsDAO.UpdateBalance(newBalance, userid);

        //返回充值后余额
        return newBalance;

    }

    //得到用户账单的多行
    public List<statementOfIncome> getuserbill(String userid) {
        List<statementOfIncome> gain = statementOfIncomeDAO.getSingleUserAllState(userid);
        return gain;

    }

    //得到所有账单信息
    public List<statementOfIncome> getAllState() {
        List<statementOfIncome> gain = statementOfIncomeDAO.getAllState();
        return gain;

    }

}